<?php
namespace Tool\Controller;
use Common\Controller\AdminbaseController;
use Home\Service\AccountService;
use Tool\Service\RepairService;
use Tool\Service\AdjustAttService;
// +----------------------------------------------------------------------
// | Date:2018年2月24日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class RepairController extends AdminbaseController{
    
    public function index(){
        $this->display();
    }
    
    
    //三八妇女节
    public function re_sanba(){
        $day = I('day');
        $day ='2018-03-08';
        if (!$day) $this->error('请设置日期');
        
        //获取女性员工工号
        $account = new AccountService();
        $user_woman =  $account->get_all_user_baseinfo('sn',['sex'=>2,'status'=>1]);
//         $user_woman = ['0153','10187','123456'];
//         $user_woman = ['10187'];
        
        $config=[
            're_sn'=>$user_woman,
            'date'=>$day,
            'time_start'=>'13:00:00',
        ];
        $adjustAttService = new AdjustAttService($config);
        $total = $adjustAttService->adjust_create();
        if(!$total) $this->error($adjustAttService->get_error());
        $this->success("操作完成,共处理{$total}条记录");
        
    }
    
    
    
    /**
     * 获取需要补打卡的名单
     * 1.当天没有任何申请；
     * 2.打卡时间是小于规定时间
     * 
     * date:2018年2月24日
     * author: EK_熊
     */
    public function re_jiayan(){
        $day = I('day');
        
        if (empty($day)) $this->error('[错误]请输入具体的日期');
        
        $dev_code = 'fzzx_1';
        $attDayModel = D('AttendanceDay');

        $clocktime = $day.' 18:00:00';
        $aly_s = $day." 12:00:00";
        $aly_e = $day." 18:00:00";
        $map['duty_off'] = ['lt',$clocktime];

        if (empty($clocktime)) $this->error('[错误]请输入正确的类型');
        
        $map['date'] = $day;
        $userbox = $attDayModel->where($map)->getField('sn,name',true);
        
        //检查当天是否申请记录
        $map_aly['sn'] = ['in',$userbox];
        $map_aly['start_time'] = ['between',[$aly_s,$aly_e]];
        $map_aly['end_time'] = ['between',[$aly_s,$aly_e]];
        
        //排除当天有申请数据的人
        $apply = M('Apply')->where($map_aly)->getField('sn',true);
        if ($apply){
            foreach ($apply as $v){
                $keys = array_keys($userbox, $v);
                unset($userbox[$keys[0]]);
            }
        }
        
        //生成打卡记录
        if ($userbox){
            $numstr = M('Attendance')->where(['dev_code'=>$dev_code])->order('dev_id desc')->getField('dev_id');
            foreach ($userbox as $k=>$v){
                $data[$k]=[
                    'dev_id'=>$numstr,
                    'name'=>"",
                    'sn'=>$v,
                    'time'=>$clocktime,
                    'dev_code'=>$dev_code                
                ];
            }
            $ret = R('Home/Loader/attendance',[$data,false]);
            
            if($ret['errcode'] !== 0) $this->error($ret['errmsg']);
            $total = count($data);
            $this->success("操作完成,共处理{$total}条记录");
        }else{
            $this->error('获取不到合适的数据');
            
        }
        
    }
}